using Microsoft.UI.Xaml.Input;
using Windows.System;
using WinUI.TableView;

namespace TableViewTest.Pages;

[Menu("行事件")]
public sealed partial class RowEventPage : Page
{
    public TestViewModel ViewModel { get; } = new();
    public RowEventPage() => InitializeComponent();
}

public partial class MyTableView : TableView
{
    /// <inheritdoc/>
    protected override void OnDoubleTapped(DoubleTappedRoutedEventArgs e)
    {
        if (SelectedItem is UserViewModel user)
        {
            user.AgeAddOne();
            e.Handled = true;
            return;
        }
        base.OnDoubleTapped(e);
    }
    /// <inheritdoc/>
    protected override void OnKeyDown(KeyRoutedEventArgs e)
    {
        if (SelectedItem is UserViewModel user)
        {
            if (e.Key == VirtualKey.Enter || e.Key == VirtualKey.Add)
            {
                user.AgeAddOne();
                e.Handled = true;
                return;
            }
            else if (e.Key == VirtualKey.Back || e.Key == VirtualKey.Subtract)
            {
                user.AgeMinusOne();
                e.Handled = true;
                return;
            }
        }
        base.OnKeyDown(e);
    }
}